﻿using ICarlifeRespository;
using ICarlifeService;
using Models.Authority;

namespace CarlifeService
{
    public class LoginService : BaseServer<Users>, ILoginService
    {
        private readonly ILoginRepository db;
        private readonly IUOfWork uOfWork;
        public LoginService(ILoginRepository db, IUOfWork uOfWork) : base(db, uOfWork)
        {
            this.db = db;
            this.uOfWork = uOfWork;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetGetLogin(string username, string password)
        {
            int namecount=db.GetAll().Where(m=>m.Login_Name.Equals(username)).Count();
            int pwdcount = db.GetAll().Where(m => m.Login_Name.Equals(username) && m.Password.Equals(password)).Count();
            if (pwdcount==0)
            {
                return -1;//用户名错误
            }
            if (namecount>0&& pwdcount == 0)
            {
                return -2;//密码错误
            }
            if (namecount > 0 && pwdcount > 0)
            {
                return 1;//登录成功
            }
            return 0;
        }
    }
}
